import {FC} from 'react'
import {useRoutes} from 'react-router-dom'
import routes from './router'
import {useAppSelector} from '@/store/hooks'
import {getAllChild,getDynamicRouteChildren} from '@/utils/transform'


const App:FC=():JSX.Element=>{
  const state=useAppSelector((state:any)=>{
     return state
  })

 
  if(state.menuModule.menus.length>0){
    console.log('菜单数据',state.menuModule.menus);
    let ary:Array<string>=[]
    getAllChild(state.menuModule.menus,ary)
    console.log('ary',ary);
    
    for(let i=0;i<routes.length;i++){
      if(routes[i].path=="/home"){
        let dyncRouteAry=routes[i].children?.filter(item=>{
          console.log('item',item.path);
          if(ary.includes(`/${item.path}`!)){
            return true
          }
        })
        routes[1].children=dyncRouteAry
      }
    }
    console.log('routes',routes);
    
   
    

  }
  

  return <>
      {useRoutes(routes)}
    </>
}
export default App